package com.ylr.admin.common.vo.menu;

import com.ylr.admin.common.enums.MenuEnum;
import com.ylr.base.common.jsr303.group.Save;
import com.ylr.base.common.jsr303.group.Update;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2023-04-21 11:27:09
 * className: MenuEntity
 * version: 1.0
 * description:
 * 	系统菜单表
 */
@Getter
@Setter
@ToString
public class MenuVo {

	/**
	 * 主键
	 */
	@NotNull(message = "主键不能为空", groups = Update.class)
	private Long id;

	/**
	 * 父菜单主键，一级菜单为0
	 */
	@NotNull(message = "父主键不能为空", groups = { Save.class, Update.class })
	private Long parentId;

	/**
	 * 父级菜单路径（‘-’分割）
	 */
	@NotBlank(message = "父级路径不能为空", groups = { Save.class, Update.class })
	private String parentPath;

	/**
	 * 所属模块
	 */
	@NotNull(message = "所属模块不能为空", groups = { Save.class, Update.class })
	private Integer module;

	/**
	 * 所属通道
	 */
	@NotNull(message = "所属通道不能为空", groups = { Save.class, Update.class })
	private Integer channel;

	/**
	 * 菜单名称
	 */
	@NotBlank(message = "菜单名称不能为空", groups = { Save.class, Update.class })
	private String menuName;

	/**
	 * 组件路径
	 */
	@NotBlank(message = "组件路径不能为空", groups = { Save.class, Update.class })
	private String path;

	/**
	 * 菜单地址/路由
	 */
	@NotBlank(message = "菜单路由不能为空", groups = { Save.class, Update.class })
	private String uri;

	/**
	 * 菜单路由名称
	 */
	@NotBlank(message = "路由名称不能为空", groups = { Save.class, Update.class })
	private String uriName;

	/**
	 * 菜单类型[0-目录 1-菜单]
	 */
	@NotNull(message = "菜单类型不能为空", groups = { Save.class, Update.class })
	private Integer type;

	/**
	 * 菜单图标
	 */
	@NotBlank(message = "菜单图标不能为空", groups = { Save.class, Update.class })
	private String icon;

	/**
	 * 排序等级
	 */
	@NotNull(message = "排序等级不能为空", groups = { Save.class, Update.class })
	private Integer sort;

	/**
	 * 是否外链[0-否 1-是]
	 */
	@NotNull(message = "是否外链不能为空", groups = { Save.class, Update.class })
	private Integer iframeStatus;

	/**
	 * 显示状态[0-显示 1-隐藏]
	 */
	@NotNull(message = "显示状态不能为空", groups = { Save.class, Update.class })
	private Integer displayStatus;

	/**
	 * 校验属性对应枚举值是否正确
	 * @return 错误描述
	 */
	public String isEnumFail() {
		if (MenuEnum.isTypeFail(type)) {
			return "菜单类型值错误";
		}
		if (MenuEnum.isIframeStatusFail(iframeStatus)) {
			return "是否外链值错误";
		}
		if (MenuEnum.isDisplayStatusFail(displayStatus)) {
			return "显示状态值错误";
		}
		return null;
	}

}
